package com.example.travel.service;

import com.example.travel.mapper.UserMapper;
import com.example.travel.pojo.User;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    public User findById(Integer id){

        return userMapper.selectById(id);
    }

    //多条件分页查询
    public PageInfo<User> PageInfoFindByParam(Integer pageNum,Integer pageSize,User user){


        return PageHelper.startPage(pageNum,pageSize).doSelectPageInfo(()->{
            userMapper.findByParam(user);
        });
    }

    //添加数据
    public int addUser(User user){

        return userMapper.insert(user);
    }

    //通过用户id获取用户信息
    public User getUserInfoById(Integer uid){

        return userMapper.selectById(uid);
    }

    //更新用户信息
    public int updateUser(User user){

        return userMapper.updateById(user);
    }

    //删除用户
    public int deleteUser(Integer uid){

        return userMapper.deleteById(uid);
    }

    //用户名查找
    public List<User> findUser(String userName){
        return userMapper.findByUserName(userName);
    }

    //通过用户名和密码查找用户信息
    public List<User> getUserByUSAndPW(User user){
        return userMapper.findByUserNameAndPassWord(user);
    }



}
